<html>
<head><meta charset="utf-8"><title>Parallel || chalk · z-archived-t-compiler/wg-rls-2.0/chalk · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/index.html">z-archived-t-compiler/wg-rls-2.0/chalk</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html">Parallel || chalk</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="189512559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189512559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189512559">(Mar 02 2020 at 17:13)</a>:</h4>
<p>This is something we've briefly discussed with Niko.</p>
<p>Currently, rust-analyzer has a single global chalk instance behind a <code>Mutex</code>. This means that rust-analyezr's typechecking is mostly single threaded. Ideally, It should be possible to typecheck all the functions in parallel.  Perhaps the answer to this <strong>is</strong> a chalk mutex, which you only hold while solving trait queries. But perhaps something more elegant and less contentious is possible.</p>



<a name="189512836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189512836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189512836">(Mar 02 2020 at 17:15)</a>:</h4>
<blockquote>
<p>This means that rust-analyezr's typechecking is mostly single threaded. Ideally, It should be possible to typecheck all the functions in parallel. Perhaps the answer to this is a chalk mutex, which you only hold while solving trait queries.</p>
</blockquote>
<p>Hmm I'd have thought we only hold the Mutex while we're solving a trait query? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> </p>
<p>I guess we could even do pooling for Chalk solvers, at the cost of some duplicate caching/memory usage...</p>



<a name="189512902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189512902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189512902">(Mar 02 2020 at 17:16)</a>:</h4>
<p>ideally the solver would be thread-safe, of course</p>



<a name="189513149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189513149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189513149">(Mar 02 2020 at 17:18)</a>:</h4>
<blockquote>
<p>Hmm I'd have thought we only hold the Mutex while we're solving a trait query? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>
</blockquote>
<p>That's true, but solving  also invokes callbacks which do resolve and other queries (I think?), so it's not like we hold mutext for a clearly bounded amount of time. In general, I am beginning to think that maybe we should try to parallelise rust-analyzer more, both beause it directly improves UX, and because we don't want to accidetly code ourselves to a single-threaded corner...</p>



<a name="189513337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189513337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189513337">(Mar 02 2020 at 17:19)</a>:</h4>
<p>I think it's reasonable to expect chalk to have <code>&amp;Solver</code> interface outside, as all the state is just caching... Trait solving doesn't logically mutate the solver.</p>



<a name="189513434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189513434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189513434">(Mar 02 2020 at 17:20)</a>:</h4>
<p>hm, yeah. I don't know if Chalk would be able to release the mutex while querying the DB though, since I think it can happen deep within the solver...</p>



<a name="189513489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/189513489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#189513489">(Mar 02 2020 at 17:21)</a>:</h4>
<p>hm ok if it only acquires the mutex when storing new solutions, maybe...</p>



<a name="190913546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/190913546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#190913546">(Mar 17 2020 at 21:32)</a>:</h4>
<p>just a quick note that I think the recursive solver you're exploring can have a good story here, <span class="user-mention" data-user-id="129457">@Florian Diebold</span> -- indeed the recursive queries can themselves even "just be" salsa queries, I suspect</p>



<a name="190913568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/190913568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#190913568">(Mar 17 2020 at 21:32)</a>:</h4>
<p>though we'd need to extend salsa to accomodate cycles</p>



<a name="190921788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel%20%7C%7C%20chalk/near/190921788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/Parallel.20.7C.7C.20chalk.html#190921788">(Mar 17 2020 at 22:57)</a>:</h4>
<p>yeah</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>